<script>
$(document).ready(function() {
	
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').click(function(e) {
	e.preventDefault();
	var url = $(this).attr('href');
	if (url.indexOf('#') == 0) {
		$(url).modal('open');
	} else {
		$.get(url, function(data) {
			$('<div class="modal hide fade">' + data + '</div>').modal();
		}).success(function() { $('input:text:visible:first').focus(); });
	}
});
	
});
</script>
<?php $stock=0; $purchase_price=0; $selling_price=0?>
<?php foreach ($products as $reports)
{
$data=$reports->opening_stock;
$data1=$reports->purchase_price;
$data2=$reports->selling_price;
$stock=intval($stock+$data);
$purchase_price=intval($purchase_price+($data1*$data));
$selling_price=intval($selling_price+($data2*$data));

}
?>

 <div class="row-fluid intelligence-data ptl tcenter ">
  <div class="span12 sers">
    <div class="span3 data-well">
      <h4 align="center" ><?php echo $stock;?></h4>
      <p class="light-text" align="center">Total Units on Hand</p>
    </div>

    <div class="span3 data-well">
      <h4 align="center" >Rs.<?php echo $purchase_price;?>.00</h4>
      <p align="center" class="light-text">Cost Value of Stock on Hand</p>
    </div>

    <div class="span3 data-well">
      <h4 align="center" >Rs.<?php echo $selling_price;?>.00</h4>
      <p align="center" class="light-text">Retail Value Stock on Hand</p>
    </div>


    <div class="span3 data-well">
      <h4 align="center" >Rs.<?php $profit=intval($selling_price-$purchase_price); echo $profit;?>.00</h4>
      <p align="center" class="light-text">Profit Value of Stock on Hand</p>
    </div>
  </div>
</div> 
<h2 class="light-text">Product List</h1>
<table class="table table-striped table-bordered" width="100%" id="example">
	<thead>
    <tr>
		<th>Product Name</th>
		<th>Product Code</th>
        <th>Category</th>
		<th>Company</th>
		<th>Branch</th>
        <th>Availabe Quantity</th>
		<th>Purchase Price</th>
		<th>Sellinng Price</th>
		<th>View Details</th>
	</tr>
    </thead><?php $stock=0;?> 
	<?php foreach ($products as $report):?>
		<tr>
			<td><?php echo $report->name; ?></td>
			<td><?php  echo $report->code; ?></td>
            <td><?php  echo $report->category_name; ?></td>
            <td><?php  echo $report->company_name; ?></td>
			<td><?php echo $report->branch;?></td>
			<td><?php  echo $report->stock." ".$report->unit_name; ?></td>
			<td><?php  echo $report->purchase_price; ?></td>
       		<td><?php  echo $report->selling_price; ?></td>
			<?php $stock=$stock+$report->opening_stock;?>
			<td><a href="<?= site_url('sales/search/getbranch_product').'/'.$report->id ;?>" title="View Details" data-toggle="modal"><i class="icon-list-alt"></i></a></td>
		</tr>
	<?php endforeach;?>
</table>

<!--<p><a href="<?php echo site_url('auth/create_report');?>">Create a new report</a> | <a href="<?php echo site_url('auth/create_group');?>">Create a new group</a>
<a href="<?php echo site_url('auth/logout');?>">Logout</a>
</p>-->


    <!-- Button to trigger modal -->
    
     
    <!-- Modal -->
